/*
 * @Date: 2022-07-22 22:52:24
 * @LastEditors: Wangjun
 * @LastEditTime: 2022-07-22 22:54:40
 * @FilePath: \lua\lualog\lualog.go
 * @Description:
 */
package lualog

import (
	"gitee.com/haodreams/golib/logs"
	lua "github.com/yuin/gopher-lua"
)

//InitLuaDB 注册默认函数
func Init(l *lua.LState) {
	l.SetGlobal("Error", l.NewFunction(Error)) //Error
	l.SetGlobal("Warn", l.NewFunction(Warn))   //warn msg
	l.SetGlobal("Info", l.NewFunction(Info))   //info msg
}

/**
 * @description: 错误信息
 * @param {*lua.LState} l
 * @return {*}
 */
func Error(l *lua.LState) int {
	msg := l.Get(1).String()
	logs.Error(l.Where(1), msg)
	return 0
}

/**
 * @description: 通知信息
 * @param {*lua.LState} l
 * @return {*}
 */
func Info(l *lua.LState) int {
	msg := l.Get(1).String()
	logs.Info(l.Where(1), msg)
	return 0
}

/**
 * @description: 警告信息
 * @param {*lua.LState} l
 * @return {*}
 */
func Warn(l *lua.LState) int {
	msg := l.Get(1).String()
	logs.Warn(l.Where(1), msg)
	return 0
}
